package java67_adv9;

import java.io.Serializable;

//.class
public class KindMan implements Serializable {
	private String name;
	private int age;
	// static{}
	{// 每次new都执行
		System.out.println("构造代码块开始执行了");
	}

	public KindMan(String n, int a) {

		this(n);
		System.out.println("两个参数的构造方法");
		// System.out.println("gou zao kaishi");
		age = a;
	}

	public KindMan(String n) {
		System.out.println("1个参数的构造方法");
		// System.out.println("gou zao kaishi");
		name = n;
	}

	public KindMan(int a) {
		System.out.println("1个int参数的构造方法");
		// System.out.println("gou zao kaishi");
		age = a;
	}

	public KindMan() {
	}

	public void selfIntro() {
		System.out.println("我叫" + name + ",今年" + age + "岁");
	}

	@Override
	public String toString() {
		return "haoren [name=" + name + ", age=" + age + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		KindMan other = (KindMan) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

	// 逻辑上是否相等
	// 指定对象是否相同的规则
	// 重写equals,我指定的方式来比较对象是否相等
//	@Override
//	public boolean equals(Object obj) {
//		// obj不是KindMan的对象
//		if (obj instanceof KindMan == false)
//			return false;
//		KindMan man = (KindMan) obj;
//		// 对象之间的比较变成了名字的比较
//		return man.name.equals(this.name);// >>>>
//	}
//
//	@Override
//	public int hashCode() {
//		return this.name.hashCode();
//	}

}
